import request from '@/utils/request';

/**
 * 分页查询用户
 */
export async function get_list(params) {
  const res = await request.post('/member/member/get_list', {
    ...params
  });
  if (res.data.code === 1) {
    return {
      list: res.data.data.row_list,
      columns: res.data.data.columns,
      searchData: res.data.data.search_area,
      count: res.data.data.page_info?.total,
      top_button: res.data.data.top_button
    };
  }
  return Promise.reject(res.data.msg);
}
export async function select_list(params) {
  const res = await request.post('/member/member/select_list', {
    ...params
  });
  if (res.data.code === 1) {
    return {
      list: res.data.data.row_list,
      columns: res.data.data.columns,
      searchData: res.data.data.search_area,
      count: res.data.data.page_info?.total,
      top_button: res.data.data.top_button
    };
  }
  return Promise.reject(res.data.msg);
}
/* 积分/礼金记录 */
export async function points_record(params) {
  const res = await request.post('/member/member/points_record', params);
  if (res.data.code === 1) {
    let columns = [
      {
        title: '操作时间',
        name: 'create_time',
        field: 'create_time',
        type: 'text',
        table: '',
        param: '',
        extra: '',
        default: '',
        class: '',
        can_edit: 0
      },
      {
        title: '操作类型',
        name: 'cate_name',
        field: 'cate_name',
        type: 'text',
        table: '',
        param: '',
        extra: '',
        default: '',
        class: '',
        can_edit: 0
      },
      {
        title: '礼金类别',
        name: 'category_name',
        field: 'category_name',
        type: 'text',
        table: '',
        param: '',
        extra: '',
        default: '',
        class: '',
        can_edit: 0
      },
      {
        title: '收入/支出',
        name: 'status_name',
        field: 'status_name',
        type: 'text',
        table: '',
        param: '',
        extra: '',
        default: '',
        class: '',
        can_edit: 0
      },
      {
        title: '数量',
        name: 'amount',
        field: 'amount',
        type: 'text',
        table: '',
        param: '',
        extra: '',
        default: '',
        class: '',
        can_edit: 0
      },
      {
        title: '相关单号',
        name: 'receipts_code',
        field: 'receipts_code',
        type: 'text',
        table: '',
        param: '',
        extra: '',
        default: '',
        class: '',
        can_edit: 0
      }
    ];
    return {
      list: res.data?.data?.list?.data,
      columns: columns,
      count: res.data?.data?.list?.total,
      data: res.data?.data
    };
  }
  return Promise.reject(res.data.msg);
}
/* 退货记录 */
export async function refund_record(params) {
  const res = await request.post('/member/member/refund_record', params);
  if (res.data.code === 1) {
    let columns = [
      {
        title: '退货单号',
        name: 'refund_sn',
        field: 'refund_sn',
        type: 'text',
        fixed: 'left',
        table: '',
        param: '',
        extra: '',
        default: '',
        class: '',
        can_edit: 0
      },
      {
        title: '退货时间',
        name: 'create_time',
        field: 'create_time',
        type: 'text',
        table: '',
        param: '',
        extra: '',
        default: '',
        class: '',
        can_edit: 0
      },
      {
        title: '所属单位',
        name: 'store_name',
        field: 'store_name',
        type: 'text',
        table: '',
        param: '',
        extra: '',
        default: '',
        class: '',
        can_edit: 0
      },
      {
        title: '货品类别',
        name: 'subclass_code_name',
        field: 'subclass_code_name',
        type: 'text',
        table: '',
        param: '',
        extra: '',
        default: '',
        class: '',
        can_edit: 0
      },
      {
        title: '原销售单',
        name: 'order_sn',
        field: 'order_sn',
        type: 'text',
        table: '',
        param: '',
        extra: '',
        default: '',
        class: '',
        can_edit: 0
      },
      {
        title: '销售时间',
        name: 'sales_time',
        field: 'sales_time',
        type: 'text',
        table: '',
        param: '',
        extra: '',
        default: '',
        class: '',
        can_edit: 0
      },
      {
        title: '会员昵称',
        name: 'nickname',
        field: 'nickname',
        type: 'text',
        table: '',
        param: '',
        extra: '',
        default: '',
        class: '',
        can_edit: 0
      },
      {
        title: '会员手机',
        name: 'mobile',
        field: 'mobile',
        type: 'text',
        table: '',
        param: '',
        extra: '',
        default: '',
        class: '',
        can_edit: 0
      },
      {
        title: '货品条码',
        name: 'bar_code',
        field: 'bar_code',
        type: 'text',
        table: '',
        param: '',
        extra: '',
        default: '',
        class: '',
        can_edit: 0
      },
      {
        title: '实售价',
        name: 'real_amount',
        field: 'real_amount',
        type: 'text',
        table: '',
        param: '',
        extra: '',
        default: '',
        class: '',
        can_edit: 0
      },
      {
        title: '数量',
        name: 'num',
        field: 'num',
        type: 'text',
        table: '',
        param: '',
        extra: '',
        default: '',
        class: '',
        can_edit: 0
      },
      {
        title: '收款金额',
        name: 'pay_amount',
        field: 'pay_amount',
        type: 'text',
        table: '',
        param: '',
        extra: '',
        default: '',
        class: '',
        can_edit: 0
      },
      {
        title: '应退金额',
        name: 'refund_amount',
        field: 'refund_amount',
        type: 'text',
        table: '',
        param: '',
        extra: '',
        default: '',
        class: '',
        can_edit: 0
      },
      {
        title: '折扣金额',
        name: 'discount_amount',
        field: 'discount_amount',
        type: 'text',
        table: '',
        param: '',
        extra: '',
        default: '',
        class: '',
        can_edit: 0
      },
      {
        title: '实退金额',
        name: 'refund_amount',
        field: 'refund_amount',
        type: 'text',
        table: '',
        param: '',
        extra: '',
        default: '',
        class: '',
        can_edit: 0
      },
      {
        title: '积分扣减',
        name: 'points',
        field: 'points',
        type: 'text',
        table: '',
        param: '',
        extra: '',
        default: '',
        class: '',
        can_edit: 0
      },
      {
        title: '礼金扣减',
        name: 'cash',
        field: 'cash',
        type: 'text',
        table: '',
        param: '',
        extra: '',
        default: '',
        class: '',
        can_edit: 0
      },
      {
        title: '销售金重(g)',
        name: 'gold_weight',
        field: 'gold_weight',
        type: 'text',
        table: '',
        param: '',
        extra: '',
        default: '',
        class: '',
        can_edit: 0
      }
    ];
    return {
      list: res.data?.data?.list?.data,
      columns: columns,
      count: res.data?.data?.list?.total,
      data: res.data?.data
    };
  }
  return Promise.reject(res.data.msg);
}

/* 消费记录 */
export async function consume_record(params) {
  const res = await request.post('/member/member/consume_record', params);
  if (res.data.code === 1) {
    return res.data;
  }
  return Promise.reject(res.data.msg);
}

/* 新建会员 */
export async function add(params) {
  const res = await request.post('/member/member/add', params);
  if (res.data.code === 1) {
    return res.data;
  }
  return Promise.reject(res.data.msg);
}
/* 编辑会员 */
export async function edit(params) {
  const res = await request.post('/member/member/edit', params);
  if (res.data.code === 1) {
    return res.data.data;
  }
  return Promise.reject(res.data.msg);
}
/* 会员详情 */
export async function detail(params) {
  const res = await request.post('/member/member/detail', params);
  if (res.data.code === 1) {
    return res.data.data;
  }
  return Promise.reject(res.data.msg);
}
/* 删除会员 */
export async function delArr(params) {
  const res = await request.post('/member/member/delete', params);
  if (res.data.code === 1) {
    return res.data.data;
  }
  return Promise.reject(res.data.msg);
}
/* 上传会员 */
export async function import_member(params) {
  const res = await request.post('/member/member/import_member', params);
  if (res.data.code === 1) {
    return res.data.data;
  }
  return Promise.reject(res.data.msg);
}
